package br.com.ebc.icontatos.controller;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.support.SpringBeanAutowiringSupport;

import br.com.ebc.icontatos.dao.LoginDAO;
import br.com.ebc.icontatos.jdbcconnection.DBLoginDAO;
import br.com.ebc.icontatos.model.LoginUsuario;

/**
 * Servlet implementation class ConfirmServlet
 */
public class ConfirmServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	private DBLoginDAO loginDB = new DBLoginDAO();
	
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ConfirmServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     * metodo que recebe o login do usuario busca no bando
     * atualiza ativando o usuario
     * e redireciona o usuario para uma tela que exibira uma mensagem de confirmacao
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	String login = request.getParameter("login");
    	LoginUsuario loginUsuario = loginDB.select(login);
    	loginDB.update(loginUsuario.getIdLoginUsuario());
    	response.sendRedirect(getServletContext().getContextPath() + "/confirmacao.jsp");
    }
    
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

}
